Sites, Bonds and Overlaps

Sites and Bonds

Bonds are derived from chem2.Bond and indicate binding interactions between sites. By default, a bond may only have two sites and a site may only have one bond.

The Bond object has a sites attribute which holds the pair of sites as a list. The following methods are available to Bond objects.

Instance Attribute Setter Getter Unsetter
id set_id(id) get_id()
sites add_sites(*sites) get_sites(**kwargs) remove_sites(*sites)

Bonds have internal class attributes that dictate bond behavior. These include:

Class Attribute Default Value Description
allowed_site_types None Tuple of allowed site classes
n_max_sites 2 Maximum number of sites per bond

For the purpose of managing bonds, Site objects have the bond instance attribute and the allowed_to_bind class attribute.

Instance Attribute Setter Getter Unsetter
bond set_bond(bond) get_bond() unset_bond()
Class Attribute Default Value Description
allowed_to_bind True Boolean controlling whether site can have a bond

Managing Site-Bond Relations

Function Site method Bond method
Attach sites to a bond set_bond(bond) add_sites(*sites)
Detach sites from a bond unset_bond() remove_sites(*sites)
Get/Filter the attached sites get_sites(**kwargs)
Get the attached bond get_molecule()

In [1]:
from wc_rules.chem2 import Molecule,Site,Bond

In [2]:
# creating sites to use for bond
class LigandBinding(Site):pass
class ReceptorBinding(Site):pass
s1,s2 = LigandBinding(id='s1'), ReceptorBinding(id='s2')

In [3]:
# Attaching sites to a bond using add_sites()
bnd = Bond(id='bnd').add_sites(s1,s2)
# Getting sites attached to a bond
bnd.get_sites()


Out[3]:
[<__main__.LigandBinding at 0x1b2a5cc15f8>,
 <__main__.ReceptorBinding at 0x1b2a5cc1630>]

In [4]:
# Filtering attached sites by id
bnd.get_sites(id='s1')


Out[4]:
[<__main__.LigandBinding at 0x1b2a5cc15f8>]

In [5]:
# Removing attached sites using remove_sites()
bnd.remove_sites(s1,s2)
bnd.get_sites()


Out[5]:
[]

In [6]:
# Attaching sites to a bond using set_bond()
bnd = Bond(id='bnd')
s1.set_bond(bnd)
s2.set_bond(bnd)
bnd.get_sites()


Out[6]:
[<__main__.LigandBinding at 0x1b2a5cc15f8>,
 <__main__.ReceptorBinding at 0x1b2a5cc1630>]

In [7]:
# Getting bond attached to sites
[s1.get_bond().get_id(), s2.get_bond().get_id()]


Out[7]:
['bnd', 'bnd']

In [8]:
# Removing bond from sites using remove_bond()
s1.unset_bond()
s2.unset_bond()
bnd.get_sites()


Out[8]:
[]

In [9]:
# Subclassing bonds to increase the number of allowed sites
class TetramerBond(Bond):
    n_max_sites = 4
    
bnd1 = TetramerBond().add_sites( Site(), Site(), Site(), Site() )
bnd2 = Bond().add_sites( Site(), Site(), Site(), Site() )
for x in [bnd1,bnd2]:
    try:
        x.verify_maximum_number_of_sites()
        print('Allowed.')
    except:
        print('Not allowed.')


Allowed.
Not allowed.

Sites and Overlaps

Overlaps are groups of sites that can only have one bond at a time. They are used to reflect groups of sites that spatially overlap with each other.

The Overlap object has a sites attribute which holds a list of sites.

Attribute Setter Getter Unsetter
id set_id(id) get_id()
sites add_sites(*sites) get_sites(**kwargs) remove_sites(*sites)

Site objects have the instance attribute overlaps, which holds a list of overlaps.

Attribute Setter Getter Unsetter
overlaps add_overlaps(*overlaps) get_overlaps(**kwargs) remove_overlaps(*overlap)

In [10]:
# Creating sites to use in overlaps
s1,s2,s3 = Site(id='s1'), Site(id='s2'), Site(id='s3')

In [11]:
# Adding overlaps using add_sites()
from wc_rules.chem2 import Overlap
olp1 = Overlap(id='olp1').add_sites(s1,s2)
# Getting overlapping sites
olp1.get_sites()


Out[11]:
[<wc_rules.chem2.Site at 0x1b2a5cd9390>,
 <wc_rules.chem2.Site at 0x1b2a5cd93c8>]

In [12]:
# Filtering overlapping sites
olp1.get_sites(id='s1')


Out[12]:
[<wc_rules.chem2.Site at 0x1b2a5cd9390>]

In [13]:
# Remove overlaps using remove_sites()
olp1.remove_sites(s1,s2)
olp1.get_sites()


Out[13]:
[]

In [14]:
# Add overlaps using add_overlaps()
s1.add_overlaps(olp1)
s2.add_overlaps(olp1)
olp1.get_sites()


Out[14]:
[<wc_rules.chem2.Site at 0x1b2a5cd9390>,
 <wc_rules.chem2.Site at 0x1b2a5cd93c8>]

In [15]:
# Get overlaps from site
s1.get_overlaps()


Out[15]:
[<wc_rules.chem2.Overlap at 0x1b2a5cd95c0>]

In [16]:
# Remove overlaps using remove_overlaps()
s1.remove_overlaps(olp1)
s2.remove_overlaps(olp1)
olp1.get_sites()


Out[16]:
[]

In [17]:
# An overlap may have many sites
olp1 = Overlap(id='s1').add_sites(s1,s2,s3)
olp1.get_sites()


Out[17]:
[<wc_rules.chem2.Site at 0x1b2a5cd9390>,
 <wc_rules.chem2.Site at 0x1b2a5cd93c8>,
 <wc_rules.chem2.Site at 0x1b2a5cd9400>]

In [18]:
# A site may have many overlaps
olp1.remove_sites(s1,s2,s3)
olp1 = Overlap(id='s1').add_sites(s1,s2)
olp2 = Overlap(id='s1').add_sites(s1,s3)
s1.get_overlaps()


Out[18]:
[<wc_rules.chem2.Overlap at 0x1b2a5cf2438>,
 <wc_rules.chem2.Overlap at 0x1b2a5cf2470>]